<template>
    <!-- 搜索头 -->
    <el-form :inline="true" :model="formInline" ref="formInline" class="demo-form-inline" size="small">
        <el-form-item>
            <el-checkbox true-label="1" false-label="0" v-model="formInline.look_del" @change="lookDelChange" border>
                查看已删门店
            </el-checkbox>
        </el-form-item>
        <el-form-item>
            <el-select placeholder="选择门店" v-model="formInline.store_id" filterable>
                <el-option v-for="item in storeList" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item>
            <dj-button size="small" @search="searchClick" />
        </el-form-item>
    </el-form>
</template>

<script>
    import {
        getStoreList,
        getAreaList,
    } from "@/api/searchHeader/dj-search-bsa";
    export default {
        props: ["categoryId"],
        data() {
            return {
                storeList: null,
                brandList: [],
                areaList: [],
                formInline: {
                    look_del: '0',
                    store_id: '',
                },
            };
        },
        activated() {
            if (!this.storeList) {
                this.getStore();
            }
        },
        methods: {
            lookDelChange() {
                this.getStore();
            },
            getStore() {
                getStoreList({ look_del: this.formInline.look_del, category_id: this.categoryId }).then(response => {
                    this.storeList = response;
                     let data = response.filter(res => 
                        res.id == this.$store.getters.optionId
                    )
                    if(data.length>0){
                        this.formInline.store_id = data[0].id;
                    } else { 
                        if(this.storeList.length > 0) {
                            this.formInline.store_id = this.storeList[0].id;
                        }
                    }
                });
            },
            // 搜索
            searchClick() {
                //第一个参数名为调用的方法名，第二个参数为需要传递的参数
                this.$emit('fetchData', this.formInline);
            },
        }
    };
</script>